package io.gitee.kenewstar.dbmq.handler;

import io.gitee.kenewstar.dbmq.ConsumerTask;
import io.gitee.kenewstar.dbmq.DbMqConfigProperties;
import io.gitee.kenewstar.dbmq.thread.DbMqConsumerThreadPool;

import java.util.List;

/**
 * @author kenewstar
 */
public class DbMqConsumerTaskHandler {

    private DbMqConsumerThreadPool dbMqConsumerThreadPool;
    private DbMqConfigProperties dbMqConfigProperties;
    private PullMessageHandler pullMessageHandler;
    private List<ConsumerTask> consumerTaskList;

    public DbMqConsumerTaskHandler() {}

    public DbMqConsumerTaskHandler(DbMqConfigProperties dbMqConfigProperties,
                                   DbMqConsumerThreadPool dbMqConsumerThreadPool,
                                   PullMessageHandler pullMessageHandler) {
        this.dbMqConfigProperties = dbMqConfigProperties;
        this.pullMessageHandler = pullMessageHandler;
        this.dbMqConsumerThreadPool = dbMqConsumerThreadPool;
    }

    public void init(List<ConsumerTask> taskList) {
        this.consumerTaskList = taskList;
    }

    public void startup() {
        dbMqConsumerThreadPool.getWorkThreadPool().initTaskList(consumerTaskList);
        dbMqConsumerThreadPool.executeScheduledTask(pullMessageHandler, dbMqConfigProperties.getPeriod());
    }



}
